#include <sys/types.h>
#include <sys/stat.h>

#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <syslog.h>

int
main()
{
   const char *file = "test.log";
   int fd = -1;

   fd = open(file, O_WRONLY | O_APPEND | O_CREAT, S_IRWXU | S_IRGRP | S_IROTH);
   if (fd < 0)
      err(1, "open");
   else {
      struct syslog_data sysdata;
      memset(&sysdata, 0, sizeof(sysdata));

      printf("open file descriptor: %d\n", fd);

      sysdata.log_file = fd;
      sysdata.connected = 0;
      sysdata.opened = 0;
      sysdata.log_stat = 0;
      sysdata.log_tag = NULL;
      sysdata.log_fac = LOG_USER;
      sysdata.log_mask = setlogmask(LOG_UPTO(LOG_DEBUG));

      openlog_r("test", LOG_USER, LOG_WARNING, &sysdata);
      syslog_r(LOG_WARNING, &sysdata, "test foo bar, foo foo bar");
      closelog_r(&sysdata);

      close(fd);
   }

   return 0;
}

